var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, i, s) {
    var o, n = arguments.length, h = n < 3 ? e : null === s ? s = Object.getOwnPropertyDescriptor(e, i) : s;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) h = Reflect.decorate(t, e, i, s); else for (var a = t.length - 1; 0 <= a; a--) (o = t[a]) && (h = (n < 3 ? o(h) : 3 < n ? o(e, i, h) : o(e, i)) || h);
    return 3 < n && h && Object.defineProperty(e, i, h), h;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("GameManager"), c = e("JoystickCommon"), l = e("PlayerModel"), d = e("EditView"), u = e("PlayerMain"), p = e("PetManager"), h = e("GameConfig"), f = e("GameData"), g = cc._decorator, m = g.ccclass, y = (g.property, 
function(o) {
    function t() {
        var t = null !== o && o.apply(this, arguments) || this;
        return t.attackCan = [ d.BlockType.BLOCK ], t.attackAim = [ l.ArmType.狙击枪, l.ArmType.导弹枪 ], 
        t.delay = 1, t.findTime = 0, t.path_idx = 0, t.path = [], t.isRun = !1, t.isDelay = !1, 
        t.isItem = !1, t;
    }
    return i(t, o), t.prototype.start = function() {
        var t = this;
        this.loadSkin(this.model.personIdx).then(function() {
            t.changeGun(t.model.gunIdx);
        });
    }, t.prototype.init = function() {
        var t, e;
        this.gameView = s.default.getInstance().gameView, this.loadModel(this.model.personIdx, this.model.gunIdx), 
        this.load(), this.hpView.init(this.getModel().MAX_HP), s.default.getInstance().matchType == s.MatchType.引导 && (this.model.ATK = 5), 
        s.default.getInstance().matchType == s.MatchType.三对三 && this.model.group != s.default.getInstance().model.curPlayer.group ? this.node.setPosition(this.gameView.getEnemyEmptyGird().scaleSelf(cc.v2(this.node.width, this.node.height)).addSelf(cc.v2((this.node.width - this.gameView.map.width) / 2, (this.node.height - this.gameView.map.height) / 2))) : this.randPos(), 
        -1 < this.model.petIdx && (t = this.gameView.getPet()) && (this.pet = t.getComponent("PlayerPet"), 
        this.pet) && (t.parent = this.gameView.layout, t.position = this.node.position, 
        t.active = !0, e = p.default.getInstance().getConfig(this.model.petIdx), console.log("宠物初始化配置,id:" + this.model.petIdx + ",config:" + e), 
        e = {
            id: e.id,
            form: Math.min(this.randPetIdx(), e.form)
        }, this.pet.initPet(this, e), t.position = this.pet.check(this.node.getPosition().add(cc.v2(60, 0)))), 
        -1 < this.model.machineIdx && (this.modelType = u.ModelType.MACHINE, this.hpView.init(this.machineModel.MAX_HP));
    }, t.prototype.initData = function(t) {
        var e = this;
        this.model = t;
        t = function() {
            for (var t = 1.5, e = 0; e < h.GC.thinkConfig.length; e++) {
                var i = h.GC.thinkConfig[e];
                if (i.r <= r.G.getRank(f.GD.level).r) {
                    t = i.t;
                    break;
                }
            }
            return t;
        }();
        this.model.IDLE < t && this.model.think > t && (this.model.think = Math.max(this.model.IDLE, t)), 
        this.schedule(function() {
            var t;
            e.isStart && e.canMove() && (0 < (t = e.findTargets().filter(function(t) {
                return e.isAttack(t);
            })).length ? (e.target = t[0], e.attack()) : e.isFill || e.isIdle || 0 < (t = e.gameView.astar.retrieve(cc.rect(e.node.x - 200, e.node.y - 200, 400, 400)).filter(function(t) {
                return t.isCanAttacked(e.model.type);
            })).length && (e.moveDir = cc.v2(t[0].node.x + t[0].node.width / 2, t[0].node.y + t[0].node.height / 2).sub(e.node.getPosition()).normalizeSelf(), 
            e.isDelay && (e.isDelay = !1, e.unschedule(e.delayAttack)), e.updateDir(e.getDir()), 
            e.doAttack() && (e._speedType = c.default.SpeedType.NORMAL, e.isItem || (e.moveDir = cc.v2(Math.random() - .5, Math.random() - .5).normalizeSelf()))), 
            e.run());
        }, this.model.think);
    }, t.prototype.randPetIdx = function() {
        for (var t = 100 * Math.random(), e = -1, i = 0; i < t && e + 1 < s.default.getInstance().petlevel.length; ) e++, 
        i += s.default.getInstance().petlevel[e];
        return Math.max(e, 0);
    }, t.prototype.loadModel = function(t, e) {
        void 0 === t && (t = f.GD.personIdx), void 0 === e && (e = f.GD.gunIdx), o.prototype.loadModel.call(this, t, e);
    }, t.prototype.isAttack = function(t) {
        var e = this;
        if (this.checkTarget(t) && this.checkTarget(this) && this.canAttack()) {
            var i = this.node.getPosition(), o = t.node.getPosition(), n = i.sub(o).mag();
            return t.model.hasBuffer(l.BufferType.隐藏中) && (-1 < this.attackAim.indexOf(this.model.type) ? n += 500 : this.getModel().RAN > 80 * s.default.getInstance().fieldgird && (n += this.getModel().RAN - 80 * s.default.getInstance().fieldgird)), 
            (-1 < this.attackAim.indexOf(this.model.type) && n < 1e3 || n <= this.getModel().RAN) && !this.gameView.astar.retrieve(this.getRect(i, o, 20)).some(function(t) {
                return -1 < e.attackCan.indexOf(t.type) && cc.Intersection.lineRect(i, o, t.node.getBoundingBox());
            });
        }
        return !1;
    }, t.prototype.attack = function() {
        var t;
        this.isFill || this.isIdle ? cc.log("attacking") : (cc.log("attack"), this.model.type == l.ArmType.暴力枪 || this.model.type == l.ArmType.闪电枪 ? this.isDelay || (this.isDelay = !0, 
        this.scheduleOnce(this.delayAttack, this.model.think + .4)) : this.model.type == l.ArmType.激光枪 ? this.isDelay || (t = this.target.node.position.sub(this.node.position).mag() / 500 * this.model.think, 
        this.isDelay = !0, this.scheduleOnce(this.delayAttack, t + .4)) : this.model.type == l.ArmType.狙击枪 || this.model.type == l.ArmType.导弹枪 ? this.isDelay || (t = this.target.node.position.sub(this.node.position).mag() / 500 * this.model.think, 
        this._speedType = c.default.SpeedType.NORMAL, this.moveDir = cc.Vec2.ZERO, this.isDelay = !0, 
        this.scheduleOnce(this.delayAttack, t + .4)) : (this.updateDir(this.getDir()), this.doAttack() && (this._speedType = c.default.SpeedType.NORMAL, 
        this.isItem || (this.moveDir = cc.v2(Math.random() - .5, Math.random() - .5).normalizeSelf()))));
    }, t.prototype.delayAttack = function() {
        this.isDelay = !1, this.canAttack() && (this.updateDir(this.getDir()), this.doAttack() && (this._speedType = c.default.SpeedType.NORMAL, 
        this.isItem || (this.moveDir = cc.v2(Math.random() - .5, Math.random() - .5).normalizeSelf())));
    }, t.prototype.run = function() {
        var t = this;
        this.model.hasBuffer(l.BufferType.月饼) || this.model.hasBuffer(l.BufferType.狗头) || (this.isRun ? cc.log("moving") : (cc.log("move"), 
        this.findTime + 1e3 * this.delay > Date.now() && this.attacking && this.checkTarget(this.target) && !this.isItem ? (this._speedType = c.default.SpeedType.NORMAL, 
        this.moveDir = this.moveDir.rotate(Math.PI / 20 * (Math.random() - .5)), this.isRun = !0, 
        this.scheduleOnce(function() {
            t.isRun = !1;
        }, this.delay)) : this.isFind() ? (this.isRun = !0, this.doRun()) : (this.isRun = !0, 
        this.scheduleOnce(function() {
            t.isRun = !1;
        }, this.delay))));
    }, t.prototype.doRun = function() {
        var t, e = this;
        -1 < this.path_idx && this.path_idx < this.path.length && (!this.canMove() || this.model.hasBuffer(l.BufferType.月饼) || this.model.hasBuffer(l.BufferType.狗头) ? this.scheduleOnce(function() {
            e.doRun();
        }, this.delay) : (t = this.gameView.astar.getPos(this.path[this.path_idx]).sub(this.node.getPosition()), 
        this.moveDir = t.normalize(), this.scheduleOnce(function() {
            e.path_idx--, e.path_idx < 0 ? e.isRun = !1 : e.doRun();
        }, Math.ceil(t.mag()) / this.model.SPE)));
    }, t.prototype.isFind = function() {
        this.model.group != s.default.getInstance().model.curPlayer.group && this.checkTarget(this.gameView.curPlayer) ? this.target = this.gameView.curPlayer : 0 < (t = this.findTargets()).length ? this.target = t[0] : this.target = null, 
        this.isItem = !1;
        var t = this.findItems();
        if (0 < t.length && (!this.checkTarget(this.target) || t[0].node.getPosition().sub(this.node.getPosition()).mag() < this.target.node.getPosition().sub(this.node.getPosition()).mag())) {
            if (this.findPath(t[0]), 1 < this.path.length) return this.isItem = !0, cc.log("ai寻路道具"), 
            this.path_idx = this.path.length - 2, !0;
        } else if (this.checkTarget(this.target) && (this.findPath(this.target), 1 < this.path.length)) return this.path_idx = this.path.length - 2, 
        !0;
        return !1;
    }, t.prototype.findPath = function(t) {
        var e = this.node.getPosition(), i = t.node.getPosition(), s = this.gameView.astar.getGird(e), t = this.gameView.astar.getGird(i);
        this.gameView.astar.retrieve(this.getRect(e, i, 40)).some(function(t) {
            return cc.Intersection.lineRect(e, i, t.node.getBoundingBox());
        }) ? (cc.log("findPath"), this.path = this.gameView.astar.findPath(s, t), this.gameView.astar.floyd(this.path)) : this.path = [ t, s ], 
        this.findTime = Date.now();
    }, t.prototype.findItems = function() {
        var i = this;
        return this.gameView.items.filter(function(t) {
            return t.node;
        }).sort(function(t, e) {
            return t.node.position.sub(i.node.position).mag() - e.node.position.sub(i.node.position).mag();
        });
    }, t.prototype.update = function(t) {
        this.checkTarget(this) && (o.prototype.update.call(this, t), this.isStart && (this.isRun && (this._speedType = c.default.SpeedType.NORMAL), 
        this.updateAtkDir(this.target)));
    }, a([ m ], t);
}(u.default));

n.default = y;